package cn.easy.rest.controller;

import cn.easy.pojo.User;
import cn.easy.rest.dao.JedisClient;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Controller
public class UtilController {
    @Autowired
    private static JedisClient jedisClient;
    public static User getUserInfoFromReids(HttpServletRequest request){
        ObjectMapper objectMapper = new ObjectMapper();
        String key = request.getHeader("easylink_user_token");
        String date = jedisClient.get(key);
        User user = null;
        try {
            user = objectMapper.readValue(date, User.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return user;
    }
}
